#import "TempView.h"

@implementation TempView

- (id)initWithFrame:(NSRect)frameRect
{
	if ((self = [super initWithFrame:frameRect]) != nil) {
		_graphics = [[NSMutableArray alloc] init];
	}
	return self;
}

-(void)dealloc
{
	[_graphics release];
	[super dealloc];
}

- (void)drawRect:(NSRect)rect
{
    // The background color
    NSColor *currentColor = [NSColor whiteColor];
    // Set the current drawing color
    [currentColor set];
 	// Fill the rect
    NSRectFill([self bounds]);

//	[_graphics makeObjectsPerformSelector:@selector(setFillColor:currentColor)];
	[_graphics makeObjectsPerformSelector:@selector(draw)];
	
}

-(void)mouseDown:(NSEvent *)theEvent
{
	NSPoint loc = [theEvent locationInWindow];
	
	[_graphics insertObject:[[PIRect alloc] init] atIndex:0];
	
	loc.x -= [self frame].origin.x;
	loc.y -= [self frame].origin.y;
	NSLog( @"(%f, %f)", loc.x, loc.y);
	
	[[_graphics objectAtIndex:0] setLocation:loc];
	[[_graphics objectAtIndex:0] setWidth:50 andHeight:50];
	
	[self setNeedsDisplay:YES];
}

- (BOOL)acceptsFirstResponder
{
	return YES;
}

@end
